package com.example.uploadimage.constant;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 图片上传linux服务器的路径使用
 */
@Component
public class UploadImagePath implements InitializingBean {

	@Value("${upload.path.window}")
	private String windowPrefixPath;  // System.getProperty("user.dir") + "/images/" ;

	@Value("${upload.path.linux}")
	private String linuxPrefixPath;

//	upload.path.visitwin
//	upload.path.visitlinux
	@Value("${upload.path.visitwin}")
	private String visitBasicPathWin;

	@Value("${upload.path.visitlinux}")
	private String visitBasicPathLinux;

	public static String WindowPrefixPath;
	public static String LinuxPrefixPath;
	public static String VisitBasicPath;

	//public static String IMG_PATH ; //= System.getProperty("user.dir") + "/images/" ;

	// 定位到当前项目下的资源目录下的static文件夹作为项目的静态资源目录
	public static String IMG_UPLOAD_PATH ; //= System.getProperty("user.dir") + "/images/" ;

	/**
	 * 初始化的时候调用一次
	 * @throws Exception
	 */
	@Override
	public void afterPropertiesSet() throws Exception {


		this.WindowPrefixPath = System.getProperty("user.dir") + this.windowPrefixPath;
		this.LinuxPrefixPath = this.linuxPrefixPath;

		String os = System.getProperty("os.name"); // 判断操作系统
		if (os.toLowerCase().startsWith("win")) {  //如果是Windows系统
			IMG_UPLOAD_PATH = UploadImagePath.WindowPrefixPath;

			// 访问的前缀地址
			VisitBasicPath = this.visitBasicPathWin;
		} else {  //linux 和mac

			// 访问的前缀地址
			VisitBasicPath = this.visitBasicPathLinux;
			IMG_UPLOAD_PATH = UploadImagePath.LinuxPrefixPath;
		}
	}
}
